package com.rtp2p.rtcoresdkdemo.play

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.lifecycle.LifecycleOwner
import com.rtp2p.rtcoresdkdemo.base.BaseRecyclerView
import com.rtp2p.rtcoresdkdemo.databinding.MsgItemBinding

class MsgAdapter : BaseRecyclerView.BaseAdapter<String, MsgAdapter.MsgVH>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MsgVH {
        val binding = MsgItemBinding.inflate(LayoutInflater.from(parent.context))
        binding.lifecycleOwner = parent.context as LifecycleOwner
        return MsgVH(binding)
    }

    override fun onBindViewHolder(holder: MsgVH, position: Int) {
        getData(position)?.let { holder.update(it) }
    }

    inner class MsgVH(binding: MsgItemBinding) :
        BaseRecyclerView.BaseViewHolder<String, MsgItemBinding>(binding) {
        override fun onChange(data: String) {
            binding.msg = data
        }
    }
}